package com.codingfuture.mvc_demo.controller;

import com.codingfuture.mvc_demo.entity.Student;
import com.codingfuture.mvc_demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public List<Student> selectAll(){
        return studentService.selectAll();
    }

    @PostMapping
    public String insert(@RequestBody Student student){
        boolean value = studentService.insert(student);
        if (value){
            return "success";
        }else{
            return "error";
        }

    }

    @PutMapping
    public String update(@RequestBody Student student){
        boolean value = studentService.updateById(student);
        if (value){
            return "success";
        }else{
            return "error";
        }
    }

    @DeleteMapping
    public String delete(@RequestParam Integer id){
        boolean value =  studentService.deleteById(id);
        if (value){
            return "success";
        }else{
            return "error";
        }
    }
}
